package com.example.demo.controller;

import com.example.demo.mytest.ReadFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

@RestController
public class TestController {
    private  final  String PATH="C:/";
    @GetMapping("/readfile")
    public String readfile(){
        long startTime=System.currentTimeMillis();
        List<File> fileList=new ArrayList<>();//接受搜索到的文件的集合
        fileList = ReadFile.readFileList(PATH,fileList);
        long endTime=System.currentTimeMillis();
        String res=MessageFormat.format("递归读取：总共的文件数:{0}个,花费的时间：{1}",fileList.size(),(endTime-startTime)/1000+"s");
        return res;
    }
    @GetMapping("/readfileByThread")
    public String readfileByThread(){
        ReadFile readFile=new ReadFile();
        long startTime=System.currentTimeMillis();
        List<File> fileList = readFile.readFileListByThread(PATH);
        long endTime=System.currentTimeMillis();
        String res=MessageFormat.format("多线程读取：总共的文件数:{0}个,花费的时间：{1}",fileList.size(),(endTime-startTime)/1000+"s");
        return res;
    }
}
